package gl.android.util;

import gl.android.xmppandroidclient.R;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class NotificationUtil {
	public static void sendSimpleNotification(Context context, String title,
			String content) {

		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
				context).setSmallIcon(R.drawable.ic_launcher)
				.setContentTitle(title).setContentText(content);
		mBuilder.setTicker("New message");// 第一次提示消息的时候显示在通知栏上
		mBuilder.setNumber(12);
		mBuilder.setAutoCancel(true);// 自己维护通知的消失

		// //构建一个Intent
		// Intent resultIntent = new Intent(MainActivity.this,
		// ResultActivity.class);
		// //封装一个Intent
		// PendingIntent resultPendingIntent = PendingIntent.getActivity(
		// MainActivity.this, 0, resultIntent,
		// PendingIntent.FLAG_UPDATE_CURRENT);
		// 设置通知主题的意图
		// mBuilder.setContentIntent(resultPendingIntent);

		// 获取通知管理器对象
		NotificationManager mNotificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		mNotificationManager.notify(0, mBuilder.build());
	}

	private static final int persistenceId = 999;

	public static void sendPersistenceNotification(Context context,
			String title, String content,String activityAction) {

		NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
				context).setSmallIcon(R.drawable.ic_launcher)
				.setContentTitle(title).setContentText(content);
		mBuilder.setTicker(context.getText(R.string.app_name));// 第一次提示消息的时候显示在通知栏上
		mBuilder.setNumber(12);
		mBuilder.setAutoCancel(false);// 自己维护通知的消失
		mBuilder.setOngoing(true);
		// 构建一个Intent
		Intent resultIntent = new Intent(activityAction);
		resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		// 封装一个Intent
		PendingIntent resultPendingIntent = PendingIntent.getActivity(context,
				0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
		// 设置通知主题的意图
		mBuilder.setContentIntent(resultPendingIntent);

		// 获取通知管理器对象
		NotificationManager mNotificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		mNotificationManager.notify(persistenceId, mBuilder.build());

	}

	public static void destoryPersistenceNotification(Context context) {
		NotificationManager mNotificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		mNotificationManager.cancel(persistenceId);
	}
}
